home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / apache_1.0.5 / src / http_log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  5.0 KB  |  164 lines

  1.  
  2. /* ====================================================================
  3.  * Copyright (c) 1995 The Apache Group.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer. 
  11.  *
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in
  14.  *    the documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  * 3. All advertising materials mentioning features or use of this
  18.  *    software must display the following acknowledgment:
  19.  *    "This product includes software developed by the Apache Group
  20.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  21.  *
  22.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  23.  *    endorse or promote products derived from this software without
  24.  *    prior written permission.
  25.  *
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *
  52.  */
  53.  
  54.  
  55. /*
  56.  * http_log.c: Dealing with the logs and errors
  57.  * 
  58.  * Rob McCool
  59.  * 
  60.  */
  61.  
  62.  
  63. #include "httpd.h"
  64. #include "http_config.h"
  65. #include "http_log.h"
  66.  
  67. #include <stdarg.h>
  68.  
  69. void open_error_log(server_rec *s, pool *p)
  70. {
  71.     char *fname;
  72.   
  73.     fname = server_root_relative (p, s->error_fname);
  74.     if(!(s->error_log = pfopen(p, fname, "a"))) {
  75.         fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
  76.         perror("fopen");
  77.         exit(1);
  78.     }
  79. }
  80.  
  81. void open_logs (server_rec *s_main, pool *p)
  82. {
  83.     server_rec *virt, *q;
  84.  
  85.     open_error_log (s_main, p);
  86.  
  87.     for (virt = s_main->next; virt; virt = virt->next) {
  88.     if (virt->error_fname)
  89.     {
  90.         for (q=s_main; q != virt; q = q->next)
  91.         if (q->error_fname != NULL &&
  92.             strcmp(q->error_fname, virt->error_fname) == 0)
  93.             break;
  94.         if (q == virt) open_error_log (virt, p);
  95.         else virt->error_log = q->error_log;
  96.     }
  97.     else
  98.         virt->error_log = s_main->error_log;
  99.     }
  100. }
  101.  
  102. void error_log2stderr(server_rec *s) {
  103.     if(fileno(s->error_log) != STDERR_FILENO)
  104.         dup2(fileno(s->error_log),STDERR_FILENO);
  105. }
  106.  
  107. void log_pid(pool *p, char *pid_fname) {
  108.     FILE *pid_file;
  109.  
  110.     if (!pid_fname) return;
  111.     pid_fname = server_root_relative (p, pid_fname);
  112.     if(!(pid_file = fopen(pid_fname,"w"))) {
  113.     perror("fopen");
  114.         fprintf(stderr,"httpd: could not log pid to file %s\n", pid_fname);
  115.         exit(1);
  116.     }
  117.     fprintf(pid_file,"%ld\n",(long)getpid());
  118.     fclose(pid_file);
  119. }
  120.  
  121. void log_error(char *err, server_rec *s) {
  122.     fprintf(s->error_log, "[%s] %s\n",get_time(),err);
  123.     fflush(s->error_log);
  124. }
  125.  
  126. void
  127. log_unixerr(const char *routine, const char *file, const char *msg,
  128.         server_rec *s)
  129. {
  130.     const char *p, *q;
  131.  
  132.     p = strerror(errno);
  133.     q = get_time();
  134.  
  135.     if (file != NULL)
  136.     fprintf(s->error_log, "[%s] %s: %s: %s\n", q, routine, file, p);
  137.     else
  138.     fprintf(s->error_log, "[%s] %s: %s\n", q, routine, p);
  139.     if (msg != NULL) fprintf(s->error_log, "[%s] - %s\n", q, msg);
  140.  
  141.     fflush(s->error_log);
  142. }
  143.  
  144. void
  145. log_printf(const server_rec *s, const char *fmt, ...)
  146. {
  147.     va_list args;
  148.     
  149.     fprintf(s->error_log, "[%s] ", get_time());
  150.     va_start (args, fmt);
  151.     vfprintf (s->error_log, fmt, args);
  152.     va_end (args);
  153.  
  154.     fputc('\n', s->error_log);
  155. }
  156.  
  157. void log_reason(char *reason, char *file, request_rec *r) {
  158.     fprintf (r->server->error_log,
  159.          "[%s] access to %s failed for %s, reason: %s\n",
  160.          get_time(), file, r->connection->remote_name, reason);
  161.     fflush (r->server->error_log);
  162. }
  163.  
  164.